

TARGET_NAME := hyperdm
TARGET_SUFFIX := exe
TARGET := $(TARGET_NAME).$(TARGET_SUFFIX)

CS_PREFIX := $(shell echo `cs-config --prefix`)
CS_DLLS := crystalspace-1.2-GCC.dll crystalspace_directx-1.2-GCC.dll crystalspace_opengl-1.2-GCC.dll crystalspace_windows-1.2-GCC.dll
CS_SRC_DLLS := $(addprefix $(CS_PREFIX)/, $(CS_DLLS))

RM := rm -rf

define userinfo
	@echo
	@echo \* \* \* success \* \* \*
	@echo
	@echo invocation examples:
	@echo $(TARGET_NAME)
	@echo $(TARGET_NAME) -video=opengl -mode=1024x768 -depth=32
	@echo $(TARGET_NAME) -video=software -mode=800x600 -depth=16
	@echo
	@echo also see the file data/config/video.cfg
endef


.PHONY: all clean

all: core.dll $(TARGET)
	$(userinfo)


$(CS_DLLS): $(CS_SRC_DLLS)
	$(foreach dll, $(CS_SRC_DLLS), cp $(dll) .;)

cs.dll: $(CS_DLLS)
	make -C cs

core.dll: cs.dll
	make -C core


$(TARGET): $(patsubst %.c, %.o, $(wildcard *.c))
	$(CC) -o $@ $< -Wl,-dy,core.dll $(CFLAGS) $(CXXFLAGS) $(LDFLAGS)

%.o: %.c 
	$(CC) -c $< $(CFLAGS) $(CXXFLAGS) $(LDFLAGS)


clean:
	$(RM) $(CS_DLLS)
	$(RM) $(TARGET)
	$(RM) *.o
	make -C cs clean
	make -C core clean
